<script setup>
  import { onLoad } from '@dcloudio/uni-app'
  import { ref, computed } from 'vue'
  import { toast } from '@/utils/utils'
  import { deliver } from '@/apis/task.js'

  //回单凭证照片数组
  const deliverPictureList = ref([])
  //货品照片数组
  const certificatePictureList = ref([])
  // 数据验证
  const disabledSubmitBtn = computed(() => {
    return deliverPictureList.value.length === 0 || certificatePictureList.value.length === 0
  })

  //提交按钮
  const submit = async () => {
    const formData = {
      id: query.value.id,
      deliverPictureList: deliverPictureList.value.map(({ url }) => ({ url })),
      certificatePictureList: certificatePictureList.value.map(({ url }) => ({ url })),
    }
    await deliver(formData)
    toast('提货成功，请尽快送达')
    setTimeout(uni.switchTab, 1500, { url: '/pages/task/index' })
  }

  const query = ref({})
  onLoad((_query) => {
    query.value = _query
    // console.log(query.value.id)
  })
</script>
<template>
  <view class="page-container">
    <view class="receipt-info">
      <uni-file-picker
        limit="3"
        file-mediatype="image"
        file-extname="png,jpg"
        title="请拍照上传回单凭证"
        v-model="deliverPictureList"
      ></uni-file-picker>
      <uni-file-picker
        limit="3"
        file-mediatype="image"
        file-extname="png,jpg"
        title="请拍照上传货品照片"
        v-model="certificatePictureList"
      ></uni-file-picker>
    </view>
    <button :disabled="disabledSubmitBtn" class="button" @click="submit">提交</button>
  </view>
</template>

<style lang="scss" scoped>
  .page-container {
    padding: 30rpx;
  }

  .receipt-info {
    min-height: 600rpx;
    background-color: #fff;
    padding: 20rpx 30rpx;
    border-radius: 16rpx;

    ::v-deep .uni-file-picker {
      margin-bottom: 30rpx;
    }
  }

  .button {
    height: 100rpx;
    text-align: center;
    line-height: 100rpx;
    /* #ifdef APP */
    padding-top: 4rpx;
    /* #endif */
    border-radius: 100rpx;
    margin-top: 60rpx;
    color: #fff;
    font-size: $uni-font-size-big;
    background-color: $uni-primary;

    &[disabled] {
      color: #fff;
      background-color: #fadcd9;
    }
  }
</style>
